package controllers

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/utils"
	"github.com/dailing/levlog"
	"io/ioutil"
)

type ImageGetRestfulRController struct {
	beego.Controller
}

func (c *ImageGetRestfulRController) Get() {
	imageName := c.Ctx.Input.Param(":imageName")
	if imageName == "" {
		c.Abort("404")
	}
	imageName = "data/" + imageName
	if !utils.FileExists(imageName) {
		levlog.Error("File ", imageName, "Not found")
		c.Abort("404")
	}
	fileContent, err := ioutil.ReadFile(imageName)
	levlog.E(err)
	if err != nil {
		c.Abort("404")
	}
	c.Ctx.Output.Body(fileContent)
}
